component extends="Model" output="false" {

	public void function init() {
		belongsTo(name='homeClub', modelName='Club', foreignKey='home_club_id');
		belongsTo(name='awayClub', modelName='Club', foreignKey='away_club_id');
	}

	public function getAllFixturesWithClubs() {
		var loc = {};
		loc.maxRows = 10;
		loc.startRow = 1;		

		loc.queryService = new Query();
		loc.queryService.setName('getAllFixturesWithClubs');
		loc.queryService.setDatasource(get('dataSourceName'));
		loc.result = loc.queryService.execute(sql="
			SELECT 	f.id,
					f.round_no,
					hc.name as 'home_club',
					ac.name as 'away_club'
			FROM fixtures f
			INNER JOIN clubs hc ON f.home_club_id = hc.id
			INNER JOIN clubs ac ON f.away_club_id = ac.id
			");
		return loc.result.getResult();
	}

}
